package vip.zhenzicheng.rabbitmq.topic;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import vip.zhenzicheng.rabbitmq.utils.RabbitConstant;
import vip.zhenzicheng.rabbitmq.utils.RabbitUtils;

import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.TimeoutException;

/**
 * @author zhenzicheng
 * @DESCRIPTION: topic 通配符模式
 * @DATE: 2022/04/25 4:23 PM
 */
public class WeatherBureau {
  public static void main(String[] args) throws IOException, TimeoutException {
    Map<String, String> area = new LinkedHashMap<>();
    area.put("china.hunan.changsha.20201127", "中国湖南长沙20201127天气数据");
    area.put("china.hubei.wuhan.20201127", "中国湖北武汉20201127天气数据");
    area.put("china.hunan.zhuzhou.20201127", "中国湖南株洲20201127天气数据");
    area.put("us.cal.lsj.20201127", "美国加州洛杉矶20201127天气数据");

    area.put("china.hebei.shijiazhuang.20201128", "中国河北石家庄20201128天气数据");
    area.put("china.hubei.wuhan.20201128", "中国湖北武汉20201128天气数据");
    area.put("china.henan.zhengzhou.20201128", "中国河南郑州20201128天气数据");
    area.put("us.cal.lsj.20201128", "美国加州洛杉矶20201128天气数据");

    Connection conn = RabbitUtils.getConnection();
    Channel channel = conn.createChannel();

    for (Map.Entry<String, String> entry : area.entrySet()) {
      channel.basicPublish(RabbitConstant.EXCHANGE_WEATHER_TOPIC, entry.getKey(), null, entry.getValue().getBytes());
    }
    channel.close();
    conn.close();

  }
}
